from __future__ import absolute_import
class Group(object):
    id = None
    name = None
    description = None
    default = None
    uservisible = None
    packages = None    
    langonly = None
    
    PKGTYPE_DEFAULT = "default"
    PKGTYPE_MANDATORY = "mandatory"
    PKGTYPE_OPTIONAL = "optional"
    
    def __init__(self, id, name, description=None, default=True, uservisible=True):
        self.id = id
        self.name = name
        self.description = description if description else ""
        self.default = default
        self.uservisible = uservisible
        self.packages = {}
        
    def __hash__(self):
        return hash(self.id)
        
    def __cmp__(self, other):
        return hash(self) == hash(other)
        
    def get_langonly(self):
        return self.langonly
        
    def get_id(self):
        return self.id
        
    def get_name(self):
        return self.name
     
    def get_description(self):
        return self.description
        
    # default, optional, mandatory
    def add_package(self, name, reqtype=PKGTYPE_DEFAULT):
        self.packages.setdefault(reqtype, []).append(name)
        
    def get_default_packages(self):
        return self.packages.get(self.PKGTYPE_DEFAULT, [])
    
    def get_mandatory_packages(self):
        return self.packages.get(self.PKGTYPE_MANDATORY, [])
    
    def get_optional_packages(self):
        return self.packages.get(self.PKGTYPE_OPTIONAL, [] )
        
    def get_all_packages(self):
        return set(self.get_optional_packages()+self.get_mandatory_packages()+self.get_optional_packages())
    def __repr__(self):
        return "<Group(%s, %s)>" % (self.name, len(self.get_all_packages()))    
